<?
if (!defined('MODULE_FILE')){
die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();
$objBaseDoctor 	= new BaseDoctors();
$objDoctors 	= new Doctors();
$objDepartments 	= new Departments();
$objSpecilizations 	= new Specilizations();
$objWards 	= new WardTypes();
?>
<html>
<head>
<?php require_once 'commonJS.php'; ?>
</head>
<body>
	<div style="margin-left:20px; margin-top: 10px;">
		<p>
			<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=doctors&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >Add New Doctor</a>&nbsp;
			<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=view_doctors&type=view&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >View All Doctors</a>
		</p>
	</div>
<div class="col-lg-8">
<div class="panel panel-primary">
<div class="panel-heading"><i class="fa fa-bell fa-fw"></i> Doctors</div>
<div class="panel-body">
	<form METHOD="POST" action="modules.php?file=insert_doctor&type=insert&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>" id="formSubmit" name="formSubmit" >
				<?php
				$intDoctorId = NULL;
				$intDepartmentId = NULL;
				$intSpecilizationId = NULL;
				$strFirstName = NULL;
				$strMiddleName = NULL;
				$strLastName = NULL;
				$strMobileNumber = NULL;
				$strPhoneNumber = NULL;
				$strOfficeNumber = NULL;
				$strSpecilizationDetails = NULL;
				$strListOfDgress = NULL;
				$intIsVisitor = NULL;
				$strVisitHospitalName = NULL;
				$strVisitDayName = NULL;
				$intVisitingCharges = NULL;
				$intWardId = NULL;
				$strOfficeDetails = NULL;
				$intRoomNumber = NULL;	

				if( true == isset( $_GET['doctor_id'] ) && true == valStr( $_GET['doctor_id'] ) ) {
					$intDoctorId = $_GET['doctor_id'];
					
					$objBaseDoctor = $objDoctors->fetchDoctorsById( $intDoctorId );
					
					if( true == valObj( $objBaseDoctor, 'BaseDoctors' ) ) {
						$intDoctorId 		= $objBaseDoctor->getId();
						$intDepartmentId    = $objBaseDoctor->getDepartmentId();
						$intSpecilizationId = $objBaseDoctor->getSpecilizationId();
						$strFirstName       = $objBaseDoctor->getFirstName();
						$strMiddleName      = $objBaseDoctor->getMiddleName();
						$strLastName        = $objBaseDoctor->getLastName();
						$strMobileNumber    = $objBaseDoctor->getMobileNumber();
						$strPhoneNumber     = $objBaseDoctor->getPhoneNumber();
						$strOfficeNumber    = $objBaseDoctor->getOfficeNumber();
						$strSpecilizationDetails = $objBaseDoctor->getSpecilizationDetails();
						$strListOfDgress    = $objBaseDoctor->getListOfDgress();
						$intIsVisitor       = $objBaseDoctor->getIsVisitor();
						$strVisitHospitalName = $objBaseDoctor->getVisitHospitalName();
						$strVisitDayName    = $objBaseDoctor->getVisitDayName();
						$intVisitingCharges = $objBaseDoctor->getVisitingCharges();
						$intWardId          = $objBaseDoctor->getWardId();
						$strOfficeDetails   = $objBaseDoctor->getOfficeDetails();
						$intRoomNumber      = $objBaseDoctor->getRoomNumber();
						
						
					}
				} else if( true == valObj( $objBaseDoctor, 'BaseDoctors' ) ) {
					$intDoctorId = $objBaseDoctor->fetchNextId();
				}
			?>
		<table width="80%" cellspacing="0" cellpadding="3">
           <tr><td height="10" colspan="2"><input id="doctor_id" Name="doctor_id" type="hidden"  style="width:100px;"  value="<?php echo $intDoctorId;?>"></td></tr>
          	<tr valign="top">
				<td  width="220">Department</td>
				<td>
		        <select class="validate[required]" name="department_id" id="department_id" style="width:202px;">
				<option value=''>-Select-</option>
				<?php
					$arrobjDepartment = $objDepartments->fetchAllDepartments();
					
					if( true == valStr( $arrobjDepartment ) ) {
						foreach( $arrobjDepartment as $objDepartment ) {
							echo '<option' . ( ( $intDepartmentId == $objDepartment->getId() ) ? ' selected' : '' ) . ' value=' . $objDepartment->getId() . '>' . $objDepartment->getName() . '</option>';
						}
					}
				?>
				</select>
				</td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 	<tr valign="top">
				<td  width="220">Specialization</td>
				<td>
		        <select class="validate[required]" name="specilization_id" id="specilization_id" style="width:202px;">
				<option value=''>-Select-</option>
				<?php
					$arrobjSpecilizations = $objSpecilizations->fetchAllSpecilizations();
					
					if( true == valStr( $arrobjSpecilizations ) ) {
						foreach( $arrobjSpecilizations as $objSpecilization ) {
							echo '<option' . ( ( $intSpecilizationId == $objSpecilization->getId() ) ? ' selected' : '' ) . ' value=' . $objSpecilization->getId() . '>' . $objSpecilization->getName() . '</option>';
						}
					}
				?>
				</select>
				</td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">First Name</td>
				<td><input id="first_name" Name="first_name" type="text" class="validate[required]" value="<?php echo $strFirstName; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Middle Name</td>
				<td><input id="middle_name" Name="middle_name" type="text" class="validate[required]" value="<?php echo $strMiddleName; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Last Name</td>
				<td><input id="last_name" Name="last_name" type="text" class="validate[required]" value="<?php echo $strLastName; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Phone Number</td>
				<td><input id="phone_number" Name="phone_number" type="text" value="<?php echo $strPhoneNumber; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Mobile Number</td>
				<td><input id="mobile_number" Name="mobile_number" type="text" class="validate[required]" value="<?php echo $strMobileNumber; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Office Number</td>
				<td><input id="office_number" Name="office_number" type="text" value="<?php echo $strOfficeNumber; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Specialization Details</td>
				<td><textarea name="specilization_details" rows="5" cols="40"><?php echo $strSpecilizationDetails; ?></textarea></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td> 
			</tr>
			<tr valign="top">
				<td  width="220">List Of Degree</td>
				<td><textarea name="list_of_dgress" rows="5" cols="40"><?php echo $strListOfDgress; ?></textarea></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Is Visitor</td>
				<td><input id="is_visitor" Name="is_visitor" class="validate[required]" type="text" value="<?php echo $intIsVisitor; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Visit Hospital Name</td>
				<td><textarea name="visit_hospital_name" rows="5" cols="40"><?php echo $strVisitHospitalName; ?></textarea></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Visit Day</td>
				<td><input id="visit_day_name" Name="visit_day_name" type="text" value="<?php echo $strVisitDayName; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Visiting Charges</td>
				<td><input id="visiting_charges" Name="visiting_charges" type="text" value="<?php echo $intVisitingCharges; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td  width="220">Ward Type</td>
				<td>
		        <select class="validate[required]" name="ward_id" id="ward_id" style="width:202px;">
				<option value=''>-Select-</option>
                <?php
					$arrobjWards = $objWards->fetchAllWardTypes();
					
					if( true == valStr( $arrobjWards ) ) {
						foreach( $arrobjWards as $objWard ) {
							echo '<option' . ( ( $intWardId == $objWard->getId() ) ? ' selected' : '' ) . ' value=' . $objWard->getId() . '>' . $objWard->getName() . '</option>';
						}
					}
				?>
				</select>
				</td>
			</tr>
			<tr>
			<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Office Details</td>
				<td><textarea name="office_details" rows="5" cols="40"><?php echo $strOfficeDetails; ?></textarea></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			 <tr valign="top">
				<td  width="220">Room Number</td>
				<td><input id="room_number" Name="room_number" type="text" value="<?php echo $intRoomNumber; ?>" style="width:202px;"></td>
			</tr>
			<tr>
				<td colspan="2" height="10px"></td>
			</tr>
			<tr valign="top">
				<td class="mandatory" width="220">&nbsp;</td>
				<td>
				<?php
				if( true == isset( $_GET['doctor_id'] ) && true == valStr( $_GET['doctor_id'] ) ) {
					echo "<input type=hidden name=operation value=update>";
					echo "<input type=submit value=UPDATE id=Submit name=Submit>";
				} else {
					echo "<input type=hidden name=operation value=insert>";
					echo "<input type=submit value=SUBMIT id=Submit name=Submit>";
				}
			?>
			<a href="modules.php?file=view_doctors&type=view&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>"><input type="button" name="calcle" value="Cancel" /></a>
				</td> 				
			</tr>
		</table>
</div>
</div>
</div>	
</form>
</body>
</html>